package primalgorithms.string;

public class _05IsPalindrome {
    public static boolean isPalindrome(String s) {
        int len = s.length();
        if(len == 0){
            return true;
        }
        int left = 0,right = len - 1;
        /**
         * ASCLL码表中
         *  0~9 ：48~57
         *  A~Z ：65~90
         *  a~z ：97~122
         */
        while (left < right){
            //重要方法：isLetterOrDigit()
            while (left < right && !Character.isLetterOrDigit(s.charAt(left))){
                left++;
            }
            while (left < right && !Character.isLetterOrDigit(s.charAt(right))){
                right--;
            }
            //重要方法：toLowerCase()
            if(Character.toLowerCase(s.charAt(left)) != Character.toLowerCase(s.charAt(right))){
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
}
